package com.hsq.ndmall.mall.controller;

import java.util.Arrays;
import java.util.Map;

//import org.apache.shiro.authz.annotation.RequiresPermissions;
import com.hsq.ndmall.mall.system.SystemConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.ApiOperation;
import com.hsq.ndmall.mall.entity.SystemEntity;
import com.hsq.ndmall.mall.service.SystemService;
import com.hsq.ndmall.common.utils.PageUtils;
import com.hsq.ndmall.common.utils.R;
import io.swagger.annotations.Api;


/**
 * 系统配置表
 *
 * @author Mr.Huang
 * @email 1607922199@qq.com
 * @date 2021-08-11 22:16:22
 */
@Api(tags = "SystemController", description = "系统配置表服务")
@RestController
@RequestMapping("mall/system")
public class SystemController {
    @Autowired
    private SystemService systemService;

    /**
     * 列表
     */
    @GetMapping("/list")
    //@RequiresPermissions("mall:system:list")
    @ApiOperation("获取所有系统配置表信息")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = systemService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    //@RequiresPermissions("mall:system:info")
    @ApiOperation("获取指定id的系统配置表详情")
    public R info(@PathVariable("id") Integer id){
		SystemEntity system = systemService.getById(id);

        return R.ok().put("system", system);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    @ApiOperation("添加系统配置表信息")
    //@RequiresPermissions("mall:system:save")
    public R save(@RequestBody SystemEntity system){
		systemService.save(system);

        return R.ok();
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    @ApiOperation("更新指定id系统配置表信息")
    //@RequiresPermissions("mall:system:update")
    public R update(@RequestBody SystemEntity system){
		systemService.updateById(system);

        return R.ok();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
    @ApiOperation("删除指定id系统配置表信息")
    //@RequiresPermissions("mall:system:delete")
    public R delete(@RequestBody Integer[] ids){
		systemService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    @GetMapping("/freight_limit")
    public R getFreightLimit(){
        return R.ok().put("freight_limit", SystemConfig.getFreightLimit());
    }

    @GetMapping("/freight")
    public R getFreight(){
        return R.ok().put("freight",SystemConfig.getFreight());
    }

}
